import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from common.base import Base

from common.functions import open_browser


class LoginPage(Base):
    login_url = 'http://139.129.26.163/user.php'

    def input_username(self, username):
        self.find_element((By.NAME, 'username')).send_keys(username)

    def input_password(self, password):
        self.find_element((By.NAME, 'password')).send_keys(password)

    def login(self):
        self.click((By.CLASS_NAME, 'us_Submit'))

    # 地址页面重新写一个页面，写在address_Page页面
    # def click_user(self):
    #     self.click((By.LINK_TEXT,'用户中心'))
    #
    # def click_address(self):
    #     self.click((By.XPATH, '//div[@class="userMenu"]/a[4]'))
    #
    # def select_country(self):
    #     self.find_element((By.XPATH, '//select[@name="country"]/option[2]'))
    #
    # def select_province(self, index):
    #     s1 = self.find_element((By.ID, 'selProvinces_0'))
    #     select = Select(s1)
    #     select.select_by_index(index)
    #
    # def select_city(self,index):
    #     s1 = self.find_element((By.ID, 'selCities_0'))
    #     select = Select(s1)
    #     select.select_by_index(index)
    #
    # def select_area(self, index):
    #     s1 = self.find_element((By.ID, 'selDistricts_0'))
    #     select = Select(s1)
    #     select.select_by_index(index)
    #
    # def input_name(self,name):
    #     self.find_element((By.ID, 'consignee_0')).send_keys(name)
    #
    # def input_email(self,email):
    #     self.find_element((By.ID, 'email_0')).send_keys(email)
    #
    # def input_address(self,address):
    #     self.find_element((By.ID, 'address_0')).send_keys(address)
    #
    # def input_zipcode(self, zipcode):
    #     self.find_element((By.ID, 'zipcode_0')).send_keys(zipcode)
    #
    # def input_tel(self, tel):
    #     self.find_element((By.ID, 'tel_0')).send_keys(tel)
    #
    # def input_mobile(self, mobile):
    #     self.find_element((By.ID, 'mobile_0')).send_keys(mobile)
    #
    # def click_add(self):
    #     self.click((By.NAME, 'submit'))
    #     # if True:
    #     #     print('新增成功')
    #     # else:
    #     #     print('请重新输入')
    #
    # # 再定位确认修改
    # def click_alter(self):
    #     self.click((By.XPATH, '//input[@value="确认修改"]'))
    #
    # # 定位删除和点击
    # def click_del(self):
    #     self.click((By.NAME, 'button'))
    #     time.sleep(5)
    #
    # # 弹窗取消
    # def alert_dismiss(self):
    #     alert = self.driver.switch_to.alert
    #     alert.dismiss()
    #     time.sleep(5)
    # # 再定位删除和点击
    # def click_del1(self):
    #     self.click((By.NAME, 'button'))
    #     time.sleep(5)
    #
    # #  弹窗确定
    # def alert_accept(self):
    #     alert = self.driver.switch_to.alert
    #     alert.accept()


if __name__ == '__main__':
    login = LoginPage(open_browser())
    login.max_windows()
    login.get('http://139.129.26.163/user.php')
    login.input_username('abc123')
    login.input_password('abc123')
    login.login()

    # #重新写一个页面，写在address_Page页面
    # login.click_user()
    # login.click_address()
    # login.select_country()
    # login.select_province(3)
    # login.select_city(1)
    # login.select_area(2)
    # login.input_name('name')
    # login.input_email('123456789@qq.com')
    # login.input_address('地球上')
    # login.input_zipcode(123456)
    # login.input_tel(11111111111)
    # login.input_mobile(11111111111)
    # login.click_add()
    # # 确认修改
    # login.click_alter()
    # # 删除
    # login.click_del()
    # #取消删除
    # login.alert_dismiss()
    # #再点击删除
    # login.click_del1()
    # #弹窗确认删除
    # login.alert_accept()
    # login.quit(5)
